﻿using Ldt.DataEngine.RuleAssemble;
using LdtJudge.DataEngine.Common.CommHelp;
using LdtJudge.DataEngine.Model.DataModel.SysCommon;
using System;
using System.Collections.Generic;
using System.Linq;

namespace LdtDataEngin.ModuleDetail.AnalysisModule.CaseCauseBaseInfoExtr
{
    public class B2CaseCauseExt : BCaseCauseExt
    {
        /// <summary>
        /// 民事二审案由提取
        /// </summary>
        /// <param name="caseCause">案由</param>
        /// <param name="OriginalText">原文全文</param>
        /// <param name="docID"></param>
        /// <param name="caseType">案件类型</param>
        /// <returns></returns>
        public IList<CaseCauseModel> CaseCauseExtract(string caseCause,string OriginalText,string docID,string caseType)
        {
            IList<Tuple<string, string>> crimeNameList = new List<Tuple<string, string>>();
            IList<CaseCauseModel> reList = new List<CaseCauseModel>();
            GetSysCaseCause dalCause = new GetSysCaseCause();
            string MacthKeyWord = string.Empty;
            if (string.IsNullOrEmpty(caseCause))
            {
                /// 如果案由为空
                string regexInfoCode = "MSCaseCauseID";
                if (!string .IsNullOrEmpty(regexInfoCode))
                {
                    var rowList = RuleParseClass.GetParseRegCodeList(regexInfoCode, new List<string> { OriginalText });
                    foreach (string cuseName in rowList)
                    {
                        if (!crimeNameList.Any(tup => tup.Item1 == cuseName))
                        {
                            crimeNameList.Add(new Tuple<string, string>(cuseName, OriginalText));
                        }
                    }
                }
              
            }
            else
            {
                if (caseCause.IndexOf(",") > -1)
                {
                    foreach (string cause in caseCause.Split(','))
                    {
                        crimeNameList.Add(new Tuple<string, string>(cause, "平台传入的案由，不进行案由提取！"));
                    }
                }
                else
                {
                    crimeNameList.Add(new Tuple<string, string>(caseCause, "平台传入的案由，不进行案由提取！"));

                }
            }
            
            //对获取到的案由，进行添加到数据集合操作。
            foreach (Tuple<string, string> causeName in crimeNameList)
            {
                CaseCauseModel MCause = dalCause.GetModelByCauseName(causeName.Item1, caseType);
                if (MCause != null)
                {
                    MCause.CC_Name= MCause.CC_Name;
                    MCause.MatchOrginalText = causeName.Item2;
                    reList.Add(MCause);
                }
            }
            return reList;
        }
    }
}
